//
//  NHMainTabbarViewController.m
//  LZNeiHan
//
//  Created by 梁梓烽 on 16/9/27.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "NHMainTabbarViewController.h"
#import "NHNavigationController.h"
#import "NHHomeViewController.h"
#import "NHDiscoverViewController.h"
#import "NHCheckViewController.h"
#import "NHMessageViewController.h"




@interface NHMainTabbarViewController ()

@end
@implementation NHMainTabbarViewController



+(void)initialize
{
    //设置全局tabbaritem
    UITabBarItem  *tabBarItem =[UITabBarItem appearance];
    NSDictionary *norDic =@{NSFontAttributeName:[UIFont systemFontOfSize:13]};
    [tabBarItem setTitleTextAttributes:norDic forState:UIControlStateNormal];
    
    NSDictionary *selectedDic =@{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor colorWithRed:0.42 green:0.33 blue:0.27 alpha:1]};
    [tabBarItem setTitleTextAttributes:selectedDic forState:UIControlStateSelected];
    
    
    //设置全局tabbar主题颜色
    UITabBar  *tabBar =[UITabBar appearance];
    [tabBar setBarTintColor:[UIColor colorWithRed:247 green:247 blue:247 alpha:1]];
    
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = KRandomColor;
    
    //添加子控制器  home  discover  check  message
    
    
    //home
    NHHomeViewController *homeVC =[[NHHomeViewController alloc]init];
    [self addChildViewCOntroller:homeVC WithImageName:@"home" WithTitle:@"首页"];
    
    
    
    //discover
    NHDiscoverViewController *discoverVC =[[NHDiscoverViewController alloc]init];
    [self addChildViewCOntroller:discoverVC WithImageName:@"Found" WithTitle:@"发现"];
    
    
    
    //check
    NHCheckViewController *checkVC =[[NHCheckViewController alloc]init];
    [self addChildViewCOntroller:checkVC WithImageName:@"audit" WithTitle:@"审核"];
    
    
    
    //message
    NHMessageViewController  *messageVC =[[NHMessageViewController alloc]init];
    [self addChildViewCOntroller:messageVC WithImageName:@"newstab" WithTitle:@"消息"];
    
    
}

/** 
 
 给tabbarcontroller添加子控制器
 
 */
-(void)addChildViewCOntroller:(UIViewController *)viewController WithImageName:(NSString *)imageName  WithTitle:(NSString *)title
{
    
    NHNavigationController *NHNav = [[NHNavigationController alloc]initWithRootViewController:viewController];
    
    UITabBarItem  *tabBarItem =viewController.tabBarItem;
    [tabBarItem setImage:[UIImage imageNamed:imageName]];
    NSString *selectImageName =[imageName stringByAppendingString:@"_press"];
    UIImage  *selectedImage =[[UIImage imageNamed:selectImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [tabBarItem setSelectedImage:selectedImage];
    
    [tabBarItem setTitle:title];
    
    [self addChildViewController:NHNav];

}





@end
